package com.wj.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {

	private File upload;//上传文件的内容
	private String uploadFileName;//上传文件名
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		//return super.execute();
		InputStream in=new FileInputStream(getUpload());//根据上传的文件得到输入流
		OutputStream out=new FileOutputStream("H:"+File.separator+"upload"+
		File.separator+getUploadFileName());//指定输出流地址
		int temp;
		while((temp=in.read())!=-1){//读取文件字节
			out.write(temp);//把文件写入到指定的文件中
		}
		out.close();//关闭文件的输出流
		in.close();//关闭文件的输入流
		System.out.println("H:"+File.separator+"upload"+File.separator+getUploadFileName());
		return SUCCESS;
	}
	
	
	
}
